home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / newsgroups / misc.19970929-19971216 / 000290_news@newsmaster….columbia.edu _Mon Nov 17 16:57:11 1997.msg < prev    next >
Internet Message Format  |  2020-01-01  |  18KB

  1. Return-Path: <news@newsmaster.cc.columbia.edu>
  2. Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.35.30])
  3.     by watsun.cc.columbia.edu (8.8.5/8.8.5) with ESMTP id QAA21902
  4.     for <kermit.misc@watsun.cc.columbia.edu>; Mon, 17 Nov 1997 16:57:11 -0500 (EST)
  5. Received: (from news@localhost)
  6.     by newsmaster.cc.columbia.edu (8.8.5/8.8.5) id QAA03924
  7.     for kermit.misc@watsun; Mon, 17 Nov 1997 16:57:10 -0500 (EST)
  8. Path: news.columbia.edu!news.new-york.net!news-peer.gip.net!news.gsl.net!gip.net!news-peer.sprintlink.net!news.sprintlink.net!Sprint!cpk-news-hub1.bbnplanet.com!news.bbnplanet.com!newsfeed.internetmci.com!192.48.96.125!in3.uu.net!hearst.acc.Virginia.EDU!mercury.vcu.edu!gems.vcu.edu!agnew
  9. From: agnew@gems.vcu.edu (Brainwave Surfer)
  10. Newsgroups: comp.protocols.kermit.misc
  11. Subject: Xmodem specs, uncorrupted (hopefully)
  12. Date: 14 Nov 97 08:59:38 -0400
  13. Organization: Medical College of Virginia
  14. Lines: 398
  15. Distribution: world
  16. Message-ID: <1997Nov14.085938.1@gems.vcu.edu>
  17. NNTP-Posting-Host: ruby.vcu.edu
  18. Xref: news.columbia.edu comp.protocols.kermit.misc:8075
  19.  
  20. I saw that someone had a corrupt copy of the xmodem protocol overview.
  21. i just happened to have had to hack a xfer between a Nicolet Pathfinder
  22. xmodem box and a vaxstation, and this was in the package from Jim Belonis'
  23. xmodem port to vms.  it handles binary files also (i think, but it's been
  24. 6 years)...
  25.  
  26. Jim
  27.  
  28.  
  29.  
  30. MODEM PROTOCOL OVERVIEW
  31.  
  32. 1/1/82 by Ward Christensen.  I will maintain a master copy of
  33. this.  Please pass on changes or suggestions via CBBS/Chicago
  34. at (312) 545-8086, CBBS/CPMUG (312) 849-1132 or by voice at
  35. (312) 849-6279.
  36.  
  37. Rev: 08/09/82 Ward C. Change ACK to 06H (was error as 05H)
  38.  
  39. 1/13/85 by John Byrns -- CRC option.
  40. Please pass on any reports of errors in this document or suggestions
  41. for improvement to me via Ward's/CBBS at (312) 849-1132, or by voice
  42. at (312) 885-1105.
  43.  
  44. 4/17/85 by Keith Petersen -- Merge of the two above.
  45.  
  46.  
  47.         Table of Contents
  48.  
  49.  1. DEFINITIONS
  50.  2. TRANSMISSION MEDIUM LEVEL PROTOCOL
  51.  3. MESSAGE BLOCK LEVEL PROTOCOL
  52.  4. FILE LEVEL PROTOCOL
  53.  5. DATA FLOW EXAMPLE INCLUDING ERROR RECOVERY
  54.  6. PROGRAMMING TIPS.
  55.  7. OVERVIEW OF CRC OPTION
  56.  8. MESSAGE BLOCK LEVEL PROTOCOL, CRC MODE
  57.  9. CRC CALCULATION
  58. 10. FILE LEVEL PROTOCOL, CHANGES FOR COMPATIBILITY
  59. 11. DATA FLOW EXAMPLES WITH CRC OPTION
  60.  
  61. -------- 1. DEFINITIONS.
  62.  
  63.   <soh> 01H
  64.   <eot> 04H
  65. | <ack> 06H
  66.   <nak> 15H
  67.   <can> 18H
  68.   <C>    43H
  69.  
  70. -------- 2. TRANSMISSION MEDIUM LEVEL PROTOCOL
  71.  
  72. Asynchronous, 8 data bits, no parity, one stop bit.
  73.  
  74.     The protocol imposes no restrictions on the contents of the
  75. data being transmitted.  No control characters are looked for
  76. in the 128-byte data messages.  Absolutely any kind of data may
  77. be sent - binary, ASCII, etc.  The protocol has not formally
  78. been adopted to a 7-bit environment for the transmission of
  79. ASCII-only (or unpacked-hex) data , although it could be simply
  80. by having both ends agree to AND the protocol-dependent data
  81. with 7F hex before validating it.  I specifically am referring
  82. to the checksum, and the block numbers and their ones-
  83. complement.
  84.     Those wishing to maintain compatibility of the CP/M file
  85. structure, i.e. to allow modemming ASCII files to or from CP/M
  86. systems should follow this data format:
  87.   * ASCII tabs used (09H); tabs set every 8.
  88.   * Lines terminated by CR/LF (0DH 0AH)
  89.   * End-of-file indicated by ^Z, 1AH.  (one or more)
  90.   * Data is variable length, i.e. should be considered a
  91.     continuous stream of data bytes, broken into 128-byte
  92.     chunks purely for the purpose of transmission.
  93.   * A CP/M "peculiarity": If the data ends exactly on a
  94.     128-byte boundary, i.e. CR in 127, and LF in 128, a
  95.     subsequent sector containing the ^Z EOF character(s)
  96.     is optional, but is preferred.  Some utilities or
  97.     user programs still do not handle EOF without ^Zs.
  98.   * The last block sent is no different from others, i.e.
  99.     there is no "short block". 
  100.  
  101. -------- 3. MESSAGE BLOCK LEVEL PROTOCOL
  102.  
  103.  Each block of the transfer looks like:
  104. <SOH><blk #><255-blk #><--128 data bytes--><cksum>
  105.     in which:
  106. <SOH>        = 01 hex
  107. <blk #>     = binary number, starts at 01 increments by 1, and
  108.           wraps 0FFH to 00H (not to 01)
  109. <255-blk #> = blk # after going thru 8080 "CMA" instr, i.e.
  110.           each bit complemented in the 8-bit block number.
  111.           Formally, this is the "ones complement".
  112. <cksum>     = the sum of the data bytes only.  Toss any carry.
  113.  
  114. -------- 4. FILE LEVEL PROTOCOL
  115.  
  116. ---- 4A. COMMON TO BOTH SENDER AND RECEIVER:
  117.  
  118.     All errors are retried 10 times.  For versions running with
  119. an operator (i.e. NOT with XMODEM), a message is typed after 10
  120. errors asking the operator whether to "retry or quit".
  121.     Some versions of the protocol use <can>, ASCII ^X, to
  122. cancel transmission.  This was never adopted as a standard, as
  123. having a single "abort" character makes the transmission
  124. susceptible to false termination due to an <ack> <nak> or <soh>
  125. being corrupted into a <can> and cancelling transmission.
  126.     The protocol may be considered "receiver driven", that is,
  127. the sender need not automatically re-transmit, although it does
  128. in the current implementations.
  129.  
  130. ---- 4B. RECEIVE PROGRAM CONSIDERATIONS:
  131.  
  132.     The receiver has a 10-second timeout.  It sends a <nak>
  133. every time it times out.  The receiver's first timeout, which
  134. sends a <nak>, signals the transmitter to start.  Optionally,
  135. the receiver could send a <nak> immediately, in case the sender
  136. was ready.  This would save the initial 10 second timeout.
  137. However, the receiver MUST continue to timeout every 10 seconds
  138. in case the sender wasn't ready.
  139.     Once into a receiving a block, the receiver goes into a
  140. one-second timeout for each character and the checksum.  If the
  141. receiver wishes to <nak> a block for any reason (invalid
  142. header, timeout receiving data), it must wait for the line to
  143. clear.  See "programming tips" for ideas
  144.     Synchronizing:  If a valid block number is received, it
  145. will be: 1) the expected one, in which case everything is fine;
  146. or 2) a repeat of the previously received block.  This should
  147. be considered OK, and only indicates that the receivers <ack>
  148. got glitched, and the sender re-transmitted; 3) any other block
  149. number indicates a fatal loss of synchronization, such as the
  150. rare case of the sender getting a line-glitch that looked like
  151. an <ack>.  Abort the transmission, sending a <can>
  152.  
  153. ---- 4C. SENDING PROGRAM CONSIDERATIONS.
  154.  
  155.     While waiting for transmission to begin, the sender has
  156. only a single very long timeout, say one minute.  In the
  157. current protocol, the sender has a 10 second timeout before
  158. retrying.  I suggest NOT doing this, and letting the protocol
  159. be completely receiver-driven.  This will be compatible with
  160. existing programs.
  161.     When the sender has no more data, it sends an <eot>, and
  162. awaits an <ack>, resending the <eot> if it doesn't get one.
  163. Again, the protocol could be receiver-driven, with the sender
  164. only having the high-level 1-minute timeout to abort.
  165.  
  166. -------- 5. DATA FLOW EXAMPLE INCLUDING ERROR RECOVERY
  167.  
  168. Here is a sample of the data flow, sending a 3-block message.
  169. It includes the two most common line hits - a garbaged block,
  170. and an <ack> reply getting garbaged.  <xx> represents the
  171. checksum byte.
  172.  
  173. SENDER                    RECEIVER
  174.                 times out after 10 seconds,
  175.             <---        <nak>
  176. <soh> 01 FE -data- <xx> --->
  177.             <---        <ack>
  178. <soh> 02 FD -data- xx    --->    (data gets line hit)
  179.             <---        <nak>
  180. <soh> 02 FD -data- xx    --->
  181.             <---        <ack>
  182. <soh> 03 FC -data- xx    --->
  183.    (ack gets garbaged)  <---        <ack>
  184. <soh> 03 FC -data- xx    --->        <ack>
  185. <eot>            --->
  186.             <---        <ack>
  187.  
  188. -------- 6. PROGRAMMING TIPS.
  189.  
  190. * The character-receive subroutine should be called with a
  191. parameter specifying the number of seconds to wait.  The
  192. receiver should first call it with a time of 10, then <nak> and
  193. try again, 10 times.
  194.   After receiving the <soh>, the receiver should call the
  195. character receive subroutine with a 1-second timeout, for the
  196. remainder of the message and the <cksum>.  Since they are sent
  197. as a continuous stream, timing out of this implies a serious
  198. like glitch that caused, say, 127 characters to be seen instead
  199. of 128.
  200.  
  201. * When the receiver wishes to <nak>, it should call a "PURGE"
  202. subroutine, to wait for the line to clear.  Recall the sender
  203. tosses any characters in its UART buffer immediately upon
  204. completing sending a block, to ensure no glitches were mis-
  205. interpreted.
  206.   The most common technique is for "PURGE" to call the
  207. character receive subroutine, specifying a 1-second timeout,
  208. and looping back to PURGE until a timeout occurs.  The <nak> is
  209. then sent, ensuring the other end will see it.
  210.  
  211. * You may wish to add code recommended by John Mahr to your
  212. character receive routine - to set an error flag if the UART
  213. shows framing error, or overrun.  This will help catch a few
  214. more glitches - the most common of which is a hit in the high
  215. bits of the byte in two consecutive bytes.  The <cksum> comes
  216. out OK since counting in 1-byte produces the same result of
  217. adding 80H + 80H as with adding 00H + 00H.
  218.  
  219. -------- 7. OVERVIEW OF CRC OPTION
  220.  
  221. The CRC used in the Modem Protocol is an alternate form of block check
  222. which provides more robust error detection than the original checksum.
  223. Andrew S. Tanenbaum says in his book, Computer Networks, that the
  224. CRC-CCITT used by the Modem Protocol will detect all single and double
  225. bit errors, all errors with an odd number of bits, all burst errors of
  226. length 16 or less, 99.997% of 17-bit error bursts, and 99.998% of
  227. 18-bit and longer bursts.
  228.  
  229. The changes to the Modem Protocol to replace the checksum with the CRC
  230. are straight forward. If that were all that we did we would not be
  231. able to communicate between a program using the old checksum protocol
  232. and one using the new CRC protocol. An initial handshake was added to
  233. solve this problem. The handshake allows a receiving program with CRC
  234. capability to determine whether the sending program supports the CRC
  235. option, and to switch it to CRC mode if it does. This handshake is
  236. designed so that it will work properly with programs which implement
  237. only the original protocol. A description of this handshake is
  238. presented in section 10.
  239.  
  240. -------- 8. MESSAGE BLOCK LEVEL PROTOCOL, CRC MODE
  241.  
  242.  Each block of the transfer in CRC mode looks like:
  243. <SOH><blk #><255-blk #><--128 data bytes--><CRC hi><CRC lo>
  244.     in which:
  245. <SOH>          = 01 hex
  246. <blk #>     = binary number, starts at 01 increments by 1, and
  247.           wraps 0FFH to 00H (not to 01)
  248. <255-blk #> = ones complement of blk #.
  249. <CRC hi>    = byte containing the 8 hi order coefficients of the CRC.
  250. <CRC lo>    = byte containing the 8 lo order coefficients of the CRC.
  251.           See the next section for CRC calculation.
  252.  
  253. -------- 9. CRC CALCULATION
  254.  
  255. ---- 9A. FORMAL DEFINITION OF THE CRC CALCULATION
  256.  
  257. To calculate the 16 bit CRC the message bits are considered to be the
  258. coefficients of a polynomial. This message polynomial is first
  259. multiplied by X^16 and then divided by the generator polynomial
  260. (X^16 + X^12 + X^5 + 1) using modulo two arithemetic. The remainder
  261. left after the division is the desired CRC. Since a message block in
  262. the Modem Protocol is 128 bytes or 1024 bits, the message polynomial
  263. will be of order X^1023. The hi order bit of the first byte of the
  264. message block is the coefficient of X^1023 in the message polynomial.
  265. The lo order bit of the last byte of the message block is the
  266. coefficient of X^0 in the message polynomial.
  267.  
  268. ---- 9B. EXAMPLE OF CRC CALCULATION WRITTEN IN C
  269.  
  270. /*
  271. This function calculates the CRC used by the "Modem Protocol"
  272. The first argument is a pointer to the message block. The second
  273. argument is the number of bytes in the message block. The message
  274. block used by the Modem Protocol contains 128 bytes.
  275. The function return value is an integer which contains the CRC. The
  276. lo order 16 bits of this integer are the coefficients of the CRC. The
  277. The lo order bit is the lo order coefficient of the CRC.
  278. */
  279.  
  280. int calcrc(ptr, count) char *ptr; int count; {
  281.  
  282.     int crc, i;
  283.  
  284.     crc = 0;
  285.     while(--count >= 0) {
  286.     crc = crc ^ (int)*ptr++ << 8;
  287.     for(i = 0; i < 8; ++i)
  288.         if(crc & 0x8000)
  289.         crc = crc << 1 ^ 0x1021;
  290.         else
  291.         crc = crc << 1;
  292.     }
  293.     return (crc & 0xFFFF);
  294.     }
  295.  
  296. -------- 10. FILE LEVEL PROTOCOL, CHANGES FOR COMPATIBILITY
  297.  
  298. ---- 10A. COMMON TO BOTH SENDER AND RECEIVER:
  299.  
  300. The only change to the File Level Protocol for the CRC option is the
  301. initial handshake which is used to determine if both the sending and
  302. the receiving programs support the CRC mode. All Modem Programs should
  303. support the checksum mode for compatibility with older versions.
  304. A receiving program that wishes to receive in CRC mode implements the
  305. mode setting handshake by sending a <C> in place of the initial <nak>.
  306. If the sending program supports CRC mode it will recognize the <C> and
  307. will set itself into CRC mode, and respond by sending the first block
  308. as if a <nak> had been received. If the sending program does not
  309. support CRC mode it will not respond to the <C> at all. After the
  310. receiver has sent the <C> it will wait up to 3 seconds for the <soh>
  311. that starts the first block. If it receives a <soh> within 3 seconds
  312. it will assume the sender supports CRC mode and will proceed with the
  313. file exchange in CRC mode. If no <soh> is received within 3 seconds
  314. the receiver will switch to checksum mode, send a <nak>, and proceed
  315. in checksum mode. If the receiver wishes to use checksum mode it
  316. should send an initial <nak> and the sending program should respond to
  317. the <nak> as defined in the original Modem Protocol. After the mode
  318. has been set by the initial <C> or <nak> the protocol follows the
  319. original Modem Protocol and is identical whether the checksum or CRC
  320. is being used.
  321.  
  322. ---- 10B. RECEIVE PROGRAM CONSIDERATIONS:
  323.  
  324. There are at least 4 things that can go wrong with the mode setting
  325. handshake.
  326.   1. the initial <C> can be garbled or lost.
  327.   2. the initial <soh> can be garbled.
  328.   3. the initial <C> can be changed to a <nak>.
  329.   4. the initial <nak> from a receiver which wants to receive in
  330.      checksum can be changed to a <C>.
  331.  
  332. The first problem can be solved if the receiver sends a second <C>
  333. after it times out the first time. This process can be repeated
  334. several times. It must not be repeated a too many times before sending
  335. a <nak> and switching to checksum mode or a sending program without
  336. CRC support may time out and abort. Repeating the <C> will also fix
  337. the second problem if the sending program cooperates by responding as
  338. if a <nak> were received instead of ignoring the extra <C>.
  339.  
  340. It is possible to fix problems 3 and 4 but probably not worth the
  341. trouble since they will occur very infrequently. They could be fixed
  342. by switching modes in either the sending or the receiving program
  343. after a large number of successive <nak>s. This solution would risk
  344. other problems however.
  345.  
  346. ---- 10C. SENDING PROGRAM CONSIDERATIONS.
  347.  
  348. The sending program should start in the checksum mode. This will
  349. insure compatibility with checksum only receiving programs. Anytime a
  350. <C> is received before the first <nak> or <ack> the sending program
  351. should set itself into CRC mode and respond as if a <nak> were
  352. received. The sender should respond to additional <C>s as if they were
  353. <nak>s until the first <ack> is received. This will assist the
  354. receiving program in determining the correct mode when the <soh> is
  355. lost or garbled. After the first <ack> is received the sending program
  356. should ignore <C>s.
  357.  
  358. -------- 11. DATA FLOW EXAMPLES WITH CRC OPTION
  359.  
  360. ---- 11A. RECEIVER HAS CRC OPTION, SENDER DOESN'T
  361.  
  362. Here is a data flow example for the case where the receiver requests
  363. transmission in the CRC mode but the sender does not support the CRC
  364. option. This example also includes various transmission errors.
  365. <xx> represents the checksum byte.
  366.  
  367. SENDER                    RECEIVER
  368.             <---        <C>
  369.                 times out after 3 seconds,
  370.             <---        <nak>
  371. <soh> 01 FE -data- <xx> --->
  372.             <---        <ack>
  373. <soh> 02 FD -data- <xx> --->    (data gets line hit)
  374.             <---        <nak>
  375. <soh> 02 FD -data- <xx> --->
  376.             <---        <ack>
  377. <soh> 03 FC -data- <xx> --->
  378.    (ack gets garbaged)  <---        <ack>
  379.                 times out after 10 seconds,
  380.             <---        <nak>
  381. <soh> 03 FC -data- <xx> --->
  382.             <---        <ack>
  383. <eot>            --->
  384.             <---        <ack>
  385.  
  386. ---- 11B. RECEIVER AND SENDER BOTH HAVE CRC OPTION
  387.  
  388. Here is a data flow example for the case where the receiver requests
  389. transmission in the CRC mode and the sender supports the CRC option.
  390. This example also includes various transmission errors.
  391. <xxxx> represents the 2 CRC bytes.
  392.  
  393. SENDER                      RECEIVER
  394.               <---          <C>
  395. <soh> 01 FE -data- <xxxx> --->
  396.               <---          <ack>
  397. <soh> 02 FD -data- <xxxx> --->      (data gets line hit)
  398.               <---          <nak>
  399. <soh> 02 FD -data- <xxxx> --->
  400.               <---          <ack>
  401. <soh> 03 FC -data- <xxxx> --->
  402.    (ack gets garbaged)      <---          <ack>
  403.                   times out after 10 seconds,
  404.               <---          <nak>
  405. <soh> 03 FC -data- <xxxx> --->
  406.               <---          <ack>
  407. <eot>              --->
  408.               <---          <ack>
  409.  
  410.             -----END-----
  411.  
  412.  
  413. -- 
  414.          /^^^\   \ /   Jim Agnew     | AGNEW@JADE.VCU.EDU NOTICE: Adding me to
  415.         /      >  ||   Neurosurgery, | a commercial mailing list is prohibited.
  416.    /\_/     '   \  /   MCV-VCU       | License will be $100.00, agreed to by
  417.  /________________>    Richmond, Va  | adding me.  THIS WILL BE ENFORCED!!!